<?php 
$user=$session->read('User');
$companyid=$session->read("companyid");
$isflag=$action->checkPermissions($user,$companyid);
?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
    	<h2>
		<?php 
		$companyname=$session->read("companyname");
		echo $html->link($companyname,"/companys/showinfosummary/".$companyid);
		?>
    	</h2>
    	<div class='clear'></div>
    </div>
    <div class="right item_add_btn">
		<?php 
			if($form->value('CompanyPatent.id')){
			$str_title=__("Edit",true);
			}else{
			$str_title=__("Add",true);
			}
    		echo $html->link(__("Cancel",true).$str_title,"/companys/patents/");
    	?>
	</div>
    <div class="clear"></div>
</div>
<?php
echo $form->create('Company', array('url' => "/companys/editpatent",'id'=>'patentform','enctype'=>'multipart/form-data','onsubmit'=>"return checkginfo()"));
?>
<div class="right_side_scollbar">
<div class="detail_info_panel">
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><font style="color:red">*</font><?php echo "知识产权" ;?>：</div>
	    <div class="form_right_e_input left"><?php echo $form->text('CompanyPatent.pname');?></div>
	    <div id='patentnamemessage' style='display:none;' class="error_message">请填写知识产权</div>
	</div>
</div>
<?php 
//专利类型
foreach($allpatents as $key=>$apatent){
 	$pid[$key] = $apatent;
 }
?>
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><font style="color:red">*</font><?php echo "产权类型" ;?>：</div>
	    <div class="form_right_e_input left"><?php echo $form->select('CompanyPatent.type_id',$pid, null, array('escape' => false));?></div>
	    <div id='patenttypeemessage' style='display:none;' class="error_message">请选择类型</div>
	</div>
</div>
<?php 
//专利状态
$state = classregistry::init('Constant')->Patentstatus;
foreach($allpatents as $key=>$apatent){
 	$pid[$key] = $apatent;
 }
 ?>
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "产权状态" ;?>：</div>
	    <div class="form_right_e_input left">
	    <?php 
	    $select=$form->value('CompanyPatent.state');
	    if(empty($id)){
	    	$select="0";
	    }
	    echo $form->select('CompanyPatent.state',$state, $select, null,null);
	    ?>
	    </div>
	</div>
</div>
<div class="details_item_line">
<div id="ApplyTime" class="details_item" >
		<div class="form_left_title left">申请时间：</div>
	    <div class="form_right_e_input left">
	    	<div class="form_right_e_input form_date_picker left">
	    		<?php echo $form->text('CompanyPatent.apply_time',array("style"=>"width:130px","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
		    </div>
	    </div>
	    
	</div>
    <div id="AcceptTime" class="details_item" style="display:none">
	    <div class="form_left_title left">受理时间：</div>
	    <div class="form_right_e_input left">
	    	<div class="form_right_e_input form_date_picker left">
		    	<?php echo $form->text('CompanyPatent.accept_time',array("style"=>"width:130px;","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
		    </div>
	    </div>   
    </div>
    <div id="AuthorizeTime" class="details_item" style="display:none">
	    <div class="form_left_title left">授权时间：</div>
	    <div class="form_right_e_input left">
	    	<div class="form_right_e_input form_date_picker left">
		    	<?php echo $form->text('CompanyPatent.authorize_time',array("style"=>"width:130px;","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
		    </div>
	    </div>
    </div>

<div id="BuyTime" class="details_item" style="display:none">
		<div class="form_left_title left">购买时间：</div>
	    <div class="form_right_e_input left">
	    	<div class="form_right_e_input form_date_picker left">
	    		<?php echo $form->text('CompanyPatent.buy_time',array("style"=>"width:130px","maxlength"=>"10","onfocus"=>"WdatePicker()"));?>
		    </div>
	    </div>
	</div>
</div>	
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "产权所属" ;?>：</div>
	    <div class="form_right_e_input left">
	    <?php 
	    $select=$form->value('CompanyPatent.to');
	    $to=classregistry::init('Constant')->Patentto;
	    if(empty($id)){
	    	$select="0";
	    }
	    echo $form->select('CompanyPatent.to',$to, $select, null,null);
	    ?>
	    </div>
	</div>
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "所属地址" ;?>：</div>
	    <div class="form_right_e_input left">
	    <?php echo $form->text('CompanyPatent.address',array("maxlength"=>"200","style"=>"width:245px"));?>
	    </div>
	</div>
</div>
<div class="details_item_line" id="PersonName" style="display:none">
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "个人姓名" ;?>：</div>
	    <div class="form_right_e_input left"><?php echo $form->text('CompanyPatent.person_name',array("maxlength"=>"20"));?></div>
	</div>
</div>
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "产权介绍" ;?>：</div>
	    <div class="form_right_e_input left"><?php echo $form->textarea('CompanyPatent.content',array('class' => 'form_textarea'));?></div>
	</div>
</div>
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"><?php echo "附件";?>：</div>
	    <div class="form_right_input left">
	     <?php if($attachments){?>
        	<div class="file_category_list">
        		<div id="filelist0" class="file_lists">
        			<ul class="file_attach">
	                	<?php
	                	$dan="'";
	                	foreach($attachments as $attachment) {
								echo "<li>";
								echo "<span>".$html->link($attachment["file_name"],'/projects/download/'.$attachment["id"],null)."</span>";
								echo "<span class='source_upload_date'>".date("Y-m-d",strtotime($attachment["created"]))."</span>";
								if($isflag){
									echo '<span class="source_upload_delete"><a title="删除" onclick="delfile(this,'.$dan.$attachment["id"].$dan.',0)" href="javascript:void(0)"></a></span>';
								}
								echo "</li>";
						}
	                	?>
	                </ul>
                </div>
            </div>
		<?php }?>
	    <div id="add1" class="left text_box"> 
			<div class="file_add_box">
				<input type="file" id="upload[]" name="upload[]" />
			</div>
		</div>
		<div class="clear"></div>
		<div id="add2" class="left filelist"></div>
		<div class="left clear">
			<div class="left add_sub_file_btn">
				<span onclick="add()" href="#"><?php echo $html->image('list-add.png')?></span>&nbsp;
				<span onclick="remove()" href="#"><?php echo $html->image('list-remove.png')?></span>
			</div>
		</div>
	 </div>
	</div>
</div>
<?php 
echo $form->hidden('CompanyPatent.owner',array('value' => $user['id'])) ;
echo $form->hidden('CompanyPatent.cid',array('value' => $companyid)) ;
echo $form->hidden('CompanyPatent.id') ;
?>
<div class="details_item_line">
	<div class="details_item">
	    <div class="form_left_title left"></div>
		<div class="form_add_submit left">
	   		 <?php echo $form->submit(__('Save',true), array("id"=>"adduser","name"=>"submit","class"=>"buttom","div"=>false));  ?>
	    </div>
	</div>
</div>
</div>
</div>
<?php echo $this->element('delfileconfirm',array("title"=>"删除提示","message"=>"你确定要删除吗？")) ?>
<script>
$("#CompanyPatentTypeId option:first").html('请选择类型');
function checkginfo(){
	if($("#CompanyPatentPname").val().trim() == ''){
		$("#patentnamemessage").css('display','block');
		return false;
	}else{
	 	$("#patentnamemessage").css('display','none');
	}
	if($("#CompanyPatentTypeId").val().trim() == ''){
		$("#patenttypeemessage").css('display','block');
		return false;
	}else{
		 $("#patenttypeemessage").css('display','none');
	}  
}
$(document).ready(function() {
	$("#CompanyPatentState").change(function() {    		
			var index=this.value;
			if(index==0){
				$("#ApplyTime").css("display","");		    
				$("#AcceptTime").css("display","none");
				$("#AuthorizeTime").css("display","none");
				$("#BuyTime").css("display","none");
			}else if(index==1){
			    $("#ApplyTime").css("display","");
				$("#AcceptTime").css("display","");				
				$("#AuthorizeTime").css("display","none");
				$("#BuyTime").css("display","none");
			}else if(index==2){
			    $("#ApplyTime").css("display","");
				$("#AcceptTime").css("display","");
				$("#AuthorizeTime").css("display","");
				$("#BuyTime").css("display","none");
			}else if(index==3){
				$("#ApplyTime").css("display","none");
				$("#AcceptTime").css("display","none");
				$("#AuthorizeTime").css("display","none");
				$("#BuyTime").css("display","");
				}
		});
	$("#CompanyPatentState").change();
	$("#CompanyPatentTo").change(function() {    		
			var index=this.value;
			if(index==0){
				$("#PersonName").css("display","none");
			}else{
				$("#PersonName").css("display","");
			}
		});
	$("#CompanyPatentTo").change();
});
</script>